package sortalg

import "fmt"

/**
简单选择排序
*/

type SimpleSelectSort struct {
	keyList []int
}

func NewSimpleSelectSort(sourceList []int) *SimpleSelectSort {
	qs := &SimpleSelectSort{
		keyList: sourceList,
	}

	qs.insertSort()

	return qs
}

func (qs *SimpleSelectSort) insertSort() {
	for i, _ := range qs.keyList {
		minTmpIndex := i
		for j := i + 1; j < len(qs.keyList); j++ {
			if qs.keyList[j] < qs.keyList[minTmpIndex] {
				minTmpIndex = j
			}
		}
		if minTmpIndex != i {
			valueTmp := qs.keyList[i]
			qs.keyList[i] = qs.keyList[minTmpIndex]
			qs.keyList[minTmpIndex] = valueTmp
		}
	}
}

func (qs *SimpleSelectSort) Print() {
	fmt.Println(qs.keyList)
}
